package org.domon.manager.sys.service.impl;

import java.util.List;

import org.domon.manager.base.service.BaseService;
import org.domon.manager.sys.mapper.SysUserMapper;
import org.domon.manager.sys.mapper.pojo.TSysUser;
import org.domon.manager.sys.model.UserInfo;
import org.domon.manager.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SysUserServiceImpl extends BaseService<UserInfo, TSysUser> implements SysUserService {

	@Autowired
	private SysUserMapper sysUserMapper;

	protected UserInfo pojoToModel(TSysUser tSysUser) {
		if (tSysUser == null) {
			return null;
		}
		UserInfo userInfo = new UserInfo();
		userInfo.setUserId(tSysUser.getId());
		userInfo.setUserName(tSysUser.getUserName());
		userInfo.setLoginName(tSysUser.getLoginName());
		return userInfo;
	}

	@Override
	protected TSysUser modelToPojo(UserInfo model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public UserInfo userAuth(String loginName, String loginPwd) {
		TSysUser user = new TSysUser();
		user.setLoginName(loginName);
		user.setLoginPwd(loginPwd);
		user.setWhereField("loginName", "loginPwd");
		List<TSysUser> tSysUsers = sysUserMapper.select(user);

		UserInfo userInfo = null;
		if (tSysUsers != null && tSysUsers.size() != 0) {
			userInfo = pojoToModel(tSysUsers.get(0));
		}
		return userInfo;
	}

	@Override
	public UserInfo queryById(int userId) {
		return pojoToModel(sysUserMapper.selectById(new TSysUser(userId)));
	}

	@Override
	public UserInfo query(UserInfo user) {
		// TODO Auto-generated method stub
		return null;
	}
}
